#include "mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
     connect(&dirPb,SIGNAL(clicked()),this,SLOT(clickDirPb()));
     connect(&savePb,SIGNAL(clicked()),this,SLOT(clickSavePb()));
     connect(&closePb,SIGNAL(clicked()),this,SLOT(clickClosePb()));
     connect(&cBox,SIGNAL(activated(int)),this,SLOT(clickcBox()));
}

MainWindow::~MainWindow()
{

}

void MainWindow::clickDirPb()
{
    dir = QFileDialog::getExistingDirectory(this,
                                            tr("Open Directory"),
                                            "/home/Tortoise",
                                            QFileDialog::ShowDirsOnly |
                                            QFileDialog::DontResolveSymlinks);
    QDir direc(dir);
    QStringList filters;

    filters << "*.cpp" << "*.txt" << "*.h";
    direc.setNameFilters(filters);

    QStringList sList = direc.entryList(QDir::Files);

    cBox.addItems(sList);

}
void MainWindow::clickcBox()
{
    qs = cBox.currentText();
    QFile pFile(dir + '/' + qs);
    if (!pFile.open(QIODevice::ReadOnly | QIODevice::Text))
             return;

    QByteArray line = pFile.readAll();
    QStandardItem *newItem = new QStandardItem(tr(line).arg(1));
    model->setItem(0, 0, newItem);
    pFile.close();
}

void MainWindow::clickClosePb()
{
   this->close();
}

void MainWindow::clickSavePb()
{

}
